const jwt = require('jsonwebtoken');
const { PRIVATE_KEY } = require('../app/config');
const service = require('../service/user.service')

class authController{
  async login(ctx,next){
    const{account,name} = ctx.user;
    const token = jwt.sign({account,name},PRIVATE_KEY,{
      expiresIn:60*30,
      algorithm:'RS256'
    })
    ctx.body = {
      account,
      token
    }
    await next();
  } 

  async detail(ctx,next){
    let {account} = ctx.user;
    const result =await service.getDetailByAccount(account);
    ctx.body = result[0];
    await next();
  }
}

module.exports = new authController();